package com.zhai.tool.utils;

import java.io.FileInputStream;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

/**
 * @Title TODO
 * @Description TODO
 * @Author CAI ZHAI
 * @Date 2021/11/25 20:44
 **/
public class NioUtils{
    
    
    
    public static void main(String[] args) throws Exception{
        FileInputStream fin = new FileInputStream("D://test.txt");
        // 获取通道
        FileChannel fc = fin.getChannel();
        // 创建级冲区
        ByteBuffer buffer = ByteBuffer.allocate(1024);// 读取数据到缓冲区
        fc.read(buffer);
        buffer.flip();
        
        while (buffer.remaining()> 0){
            byte b = buffer.get();
            System.out.println(((char)b));
            fin.close();
        }
    }
}
